#include "kernel.h"
#include "SEGGER_RTT.h"
#include "can_interface.h"
#include "obj_data.h"
#include "can_protocol.h"

TaskHandle_t canRxTask_Handler;	// 任务句柄

/**
 * @brief 与主控通信的CAN接收任务
 * 
 * @param pvParameters
 */
void cmdCanRx_task(void *pvParameters)
{
	const TickType_t time_to_wait = pdMS_TO_TICKS(10); //2ms

	uint8 port = 0;
	CanMessage canMsg = {0};
	ucan_frame canFrame = {0};

	/* can协议初始化 */
	can_protocol_init();
	while(true)
	{		
        while(can_recv_msg(port , &canMsg))
        {
            memcpy(&canFrame.m_data[0], &canMsg.m_canID, canMsg.m_dataLen + 7);
            protocol_analysis(&canFrame);
        }
		com_data.ticks++;
		// SEGGER_RTT_printf(0, "sys tick = %d\n", xTaskGetTickCount());
		vTaskDelay(time_to_wait);	// 有CAN消息时由中断唤醒进入就绪态
	}
}
